<!DOCTYPE html>
<html>
<head>
    <title>我的游记</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/userTravels.css"/>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script>
        $(function () {
            //获取当前用户
            var user = JSON.parse(sessionStorage.getItem("user"));
            //当前页的Input框
            var currentInput = $("#currentPage");
            //用于存储游记的数组容器
            var travelArr = [];

            //总页数
            var pages = 1;
            function query() {
                //获取到当前页的值
                var currentPage = currentInput.val();
                $.get('/users/' + user.id + '/travels',{currentPage:currentPage}, function (data) {
                    //合并两个数组到第一个数组上。
                    $.merge( travelArr, data.list );
                    //渲染页面
                    $('.travels').renderValues({list:travelArr},{
                        //itme表示该标签,value对应key的值
                        getHref:function (item,value) {
                            var href = $(item).data("href");
                            $(item).attr("href",href+value);
                        }
                    });
                    //设置总页数
                    pages = data.pages;
                });
                //当前页input框+1
                currentInput.val(parseInt(currentPage) + 1)
            }
            query();
            //当页面滚动条发生变化时,执行的函数
            $(window).scroll(function () {
                if($(document).scrollTop()+$(window).height()-0.2>=$(document).height()){
                    var currentPage = currentInput.val();
                    //判断是否小于等于最后一页
                    if(currentPage<=pages){
                        query();
                    }else{
                        $(document).dialog({
                            type : 'notice',
                            infoText: '已经到底了',
                            autoClose: 1000,
                        });
                    };
                };
            });

        });
    </script>

</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="profiles.html">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
            <span>我的游记</span>
        </div>
        <div class="col"></div>
    </div>
</div>

<input type="hidden" id="currentPage" name="currentPage" value="1">
<div class="container travels">
    <dl class="list" render-loop="list">
        <dd>
            <a data-href="editTravels.html?id=" render-key="list.id" render-fun="getHref">
                <img render-src="list.coverUrl">
                <h6 class="title" render-html="list.title"></h6>
                <p>最近更新时间 <span render-html="list.lastUpdateTime"></span>
                    <span class="span-right">
                        <i class="fa fa-heart"></i><span>0</span>收藏
                        <i class="fa fa-thumbs-o-up"></i><span>0</span>点赞</span>
                </p>
            </a>
        </dd>
    </dl>
</div>

</body>
</html>
